package vmcs.controller;

import vmcs.common.Constant;
import vmcs.common.VMCSException;
import vmcs.ui.interfacecontrol.*;

// Copyright 1997 ISS.
// The contents contained in this document may not be reproduced in any
// form or by any means, without the written permission of ISS, other
// than for the purpose for which it has been supplied.
//
// Author: Olivo Miotto
//

public class SimulationController {

    private ISimulatorPanel scp = null;
/**
* Reference to the MainController object.
*/     
    public  MainController        mCtrl = null;

/**
* This constructor creates a new instance of SimulationController.
* It receives the reference for MainController object.
* @param ctrl
*/     
    
    public SimulationController(MainController ctrl) {
            mCtrl = ctrl;
  //          scp = UIController.getSimulatorControlPanel(this);
    }
    
  //------------this is added to correct listener factory pattern problem  
    public void initializeSimulationController(MainController ctrl){
        //scp = ControlFactory.getSimulatorControlPanel(this);
    	scp = UIController.getSimulatorControlPanel(this);

    }

/**
* This operation returns the reference to the SimulatorControlPanel object.
* @return Simulator Control Panel
* 
* @see SimulatorControlPanel
*/     
    public ISimulatorPanel getStartUpPanel() {
            return (scp);
    }

/**
* This operation displays the Simulator Control Panel.
*/     
    public void displaySimulatorControlPanel() {
            scp.display();
    }

/**
* This operation will instruct the Main Controller to close down.
*/     
    public void stop() {
            mCtrl.closeDown();
    }

/**
* This operation will instruct all four panels of the VMCS to close down when
* instructed by the Main Controller.
*/     
    public void closeDown() {
            scp.closeDown();
    }

/**
* This operation is triggered when the Begin Simulation Button is pressed on the
* Simulator Control Panel. It will start the simulation of VMCS by activating
* the three panel buttons namely Activate Customer Panel Button, Activate Maintainer
* Panel Button, Activate Machinery Simulator Button.
*/     
    public void start() {
            scp.setPanelActive(true);
            scp.setPanelActive(Constant.SIMUL_BEGIN, false);
    }

/**
* This operation enables the Begin Simulation Button and disable the other
* buttons if FALSE is passed. If TRUE is passed the Begin Simulation Button is
* disabled and the other buttons of the Simulator Control Panel are enabled. 
* @param vl value that sets the Simulator Control Panel Buttons (Enabled/Disabled)
*/     
    public void setSimulationActive(boolean vl) {
            scp.setPanelActive(vl);
    }
    
/**
* This operation sets up the Machinery Simulator Panel.
* This will be achieved as follows:
* 1  Deactivate the Activate Machinery Simulator Button.
* 2  Display Machinery Simulator Panel with intial values set.
* 3  Deactivate the panel.
*/
    public void setupSimulator() {
            //MaintenanceController maintenanceCtrl;
            //maintenanceCtrl = mCtrl.getMaintenanceController();
            MachineryController machCtrl;

            machCtrl = mCtrl.getMachineryController();
            scp.setPanelActive(Constant.ACT_MACHINERY, false);
            //try {
                    // activate when not login
                    // always display the door locked; isOpen false
                    machCtrl.displayMachineryPanel();
                    machCtrl.displayDoorState();
    }

/**
* This operation sets up the Maintenance Panel.
* Set-up the Maintenance Panel. This will be acheived as follows:
* 1  Send a message to deactivate the Activate Maintainer Panel Button.
* 2  Send messages to instruct all its constituent objects to display 
* themselves, and also instruct them all, except for the Password Box 
* to become deactivated.
*/     
    public void setupMaintainer() {
            MaintenanceController mctrl;
            mctrl = mCtrl.getMaintenanceController();
            scp.setPanelActive(Constant.ACT_MAINTAINER, false);
            mctrl.displayMaintenancePanel();
    }

/**
* This operation sets up the Customer Panel.
* Set-up the Customer Panel. This will be acheived as follows:
* 1  Send a message to deactivate the Activate Customer Panel Button.
* 2  Send a message to the Customer Panel instructing it to 
*    display all its constituent interface objects.
* 3  Display the current values for out of stock brands and prices.
* 4  Activate the No Change Available Display (if necessary).
*/     
    public void setupCustomer() {
            TransactionController tctrl;
            tctrl = mCtrl.getTransactionController();
            scp.setPanelActive(Constant.ACT_CUSTOMER, false);
            tctrl.displayCustomerPanel();
    }

/**
* This operation returns the reference for the MainController Object
* @return Main Controller
* 
* @see MainController
*/     
    public MainController getMainController() {
            return mCtrl;
    }

}

